<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
		<title>生命体征检测云平台</title>
		<link rel="shortcut icon" href="static/logo.ico" />
		<link rel="stylesheet" href="static/css/index.css" />
		<link rel="stylesheet" href="static/layui/css/layui.css" />
		<script type="text/javascript" src="static/js/jquery.min.js"></script>
		<script src="static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="static/js/vue.js"></script>
		<script type="text/javascript" src="static/js/axios.min.js"></script>
		<style>
			html,
			body,
			#container {
				height: 100%;
				width: 100%;
			}

			.container {
				height: auto;
				width: 100%;
			}

			.container2 {
				height: auto;
				width: 100%;
			}

			.collision-btn.disable {
				background-image: none;
				color: lightgrey;
				border-color: lightgrey;
				cursor: not-allowed;
			}

			.collision-btn.disable:hover {
				background-color: #fff;
				border-color: lightgrey;
			}

			.input-card .btn {
				margin-right: .8rem;
			}

			.amap-marker {
				opacity: 0.01;
			}

			.nav-right {
				top: 1.5rem !important;
			}

			.info {
				z-index: 999 !important;
			}

			.layui-form-label {
				width: 110px;
				font-size: 14px !important;
			}

			::-webkit-input-placeholder {
				/*Webkit browsers*/
				color: #999;
				font-size: 13px;
			}

			:-moz-placeholder {
				/*Mozilla Firefox 4 to 8*/
				color: #999;
				font-size: 13px;
			}

			::moz-placeholder {
				/*Mozilla Firefox 19+*/
				color: #999;
				font-size: 13px;
			}

			:-ms-input-placeholder {
				/*Internet Explorer 10+*/
				color: #999;
				font-size: 13px;
			}

			.layui-form-pane .layui-input {
				height: 38px !important;
			}

			.layui-table th:nth-child(1) {
				width: 80px;
				text-align: center;
			}

			.layui-table td:nth-child(1) {
				width: 80px;
				text-align: center;
			}

			.layui-table th:nth-child(2) {
				width: 190px;
				text-align: center;
			}

			.layui-table td:nth-child(2) {
				width: 190px;
				text-align: center;
			}

			.layui-table th:nth-child(3) {
				width: 140px;
				text-align: center;
			}

			.layui-table td:nth-child(3) {
				width: 140px;
				text-align: center;
			}

			.layui-table th:nth-child(4) {
				width: 60px;
				text-align: center;
			}

			.layui-table td:nth-child(4) {
				width: 60px;
				text-align: center;
			}

			.layui-table th:nth-child(5) {
				text-align: left;
			}

			.layui-table td:nth-child(5) {
				text-align: left;
			}
		</style>
		<script>
			layui.use(['form', 'layedit', 'laydate', 'dropdown'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate,
					dropdown = layui.dropdown;
				dropdown.on('click(docDemoMenu1)', function(options) {
					var othis = $(this); //当前菜单列表的 DOM 对象
					console.log(options.url)

				});
				form.verify({
					title: function(value) {
						if (value.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					pass: [
						/^[\S]{6,16}$/, '密码必须6到12位，且不能出现空格'
					],
					content: function(value) {
						layedit.sync(editIndex);
					}
				});
				laydate.render({
					elem: '#date1'
				});
			});
			$(function() {
				$('.userinfo').hover(function() {

				});
			});
		</script>
	</head>
	<body>
		<div id="app">
			<div style="margin-top: 70px;background-color: #e5e5e5;"></div>
			<div class="layui-panel" style="float: left; width: 10% !important;" id="pnav">

			</div>
			<div class="container2" style="width: 90% !important; float: right;padding-left: 30px;">
				<div class="layui-fluid">
					<fieldset class="layui-elem-field layui-field-title">
						<legend>家庭成员管理</legend>
					</fieldset>
					<div class="layui-row">
						<div class="layui-col-md12" style="font-size: 18px;padding-right: 20px;">
							<!-- <a class="layui-btn layui-btn-normal" href="members_add.html"
								style="float: right;height: 30px;line-height: 26px !important;background-color: #fb0000;" v-on:click="deldata(ufitem.familyName)">删除家庭组</a>
							<a class="layui-btn layui-btn-normal" href="members_add.html"
								style="float: right;height: 30px;line-height: 26px !important;margin-right: 10px;background-color: #ff5722;">修改家庭组名称</a> -->
							<a class="layui-btn layui-btn-normal" href="members_add.html"
								style="float: right;height: 30px;line-height: 26px !important;">添加成员</a>
						</div>
					</div>
					<div class="layui-row">
						<div class="layui-col-sm12"
							style="padding: 10px;box-shadow: 0 2px 4px 0 rgba(0,0,0,.1);background: #fff;">
							<div class="grid-demo grid-demo-bg1">
								<div class="layui-row">
									<div class="layui-col-md12" style="font-size: 18px;padding: 20px;">
										<div class="layui-collapse" lay-accordion>
											<div class="layui-colla-item">
												<h2 class="layui-colla-title">被关注者</h2>
												<div class="layui-colla-content layui-show">
													<table class="layui-table" id="layuitable">
														<thead>
															<tr>
																<th>关系</th>
																<th>名字</th>
																<th>电话</th>
																<th>性别</th>
																<th>操作</th>
															</tr>
														</thead>
														<tbody>
															<tr v-for="ufitem in ufInfoData"
																v-if="ufitem.relationship=='主用户'">
																<td>{{ufitem.relationship}}</td>
																<td>{{ufitem.userName}} <span
																		style="color: #063683;">（超级管理員）</span></td>
																<td>{{ufitem.phone}}</td>
																<td v-if="ufitem.sex==1">男</td>
																<td v-if="ufitem.sex==2">女</td>
																<td>
																	<a class="layui-btn layui-btn-normal"
																		href="equipment.html"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-if="isleader!=3">修改默认设备</a>
																	<a class="layui-btn layui-btn-normal"
																		href="bed_monitoring_list.html"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-if="isleader!=3">在床检测</a>
																	<a class="layui-btn layui-btn-normal"
																		href="bed_alarm.html"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-if="isleader!=3">离床报警</a>
																	<a class="layui-btn layui-btn-normal"
																		href="warning_set_up.html"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-if="isleader!=3">预警设置</a>
																</td>
															</tr>
														</tbody>
													</table>
												</div>
											</div>
											<div class="layui-colla-item">
												<h2 class="layui-colla-title">关注者</h2>
												<div class="layui-colla-content layui-show">
													<table class="layui-table">
														<thead>
															<tr>
																<th>关系</th>
																<th>名字</th>
																<th>电话</th>
																<th>性别</th>
																<th>操作</th>
															</tr>
														</thead>
														<tbody>
															<tr v-for="ufitems in ufInfoData"
																v-if="ufitems.relationship!='主用户'">
																<td>{{ufitems.relationship}}</td>
																<td>{{ufitems.userName}} <span
																		v-if="ufitems.isleader==2"
																		style="color: #3d6eff;">(管理员)</span> </td>
																<td>{{ufitems.phone}}</td>
																<!-- <td>{{ufitems.sex}}</td> -->
																<td v-if="ufitems.sex==1">男</td>
																<td v-if="ufitems.sex==2">女</td>
																<td>
																	<a class="layui-btn layui-btn-normal"
																		href="javascript:void(0);"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-on:click="Setmanagement(ufitems.phone,2)"
																		v-if="isleader!=3">设为管理员</a>
																	<a class="layui-btn layui-btn-normal"
																		href="javascript:void(0);"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-on:click="Setmanagement(ufitems.phone,3)"
																		v-if="isleader!=3">取消管理员</a>
																	<a class="layui-btn layui-btn-normal"
																		href="javascript:void(0);"
																		style="height: 25px;line-height: 25px !important; background-color: #fff !important; color:#3d6eff;font-size: 14px;"
																		v-on:click="deldata(ufitems.phone)"
																		v-if="isleader!=3">删除</a>
																</td>
															</tr>
														</tbody>
													</table>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="info">
				<div class="nav-left">
					<a class="login"></a>
					<a class="hometext" href="index.html" v-if="uInfoData.loginType !=1">首页</a>
					<a class="hometext" href="home.html" v-if="uInfoData.loginType == 1">首页</a>
				</div>
				<div class="nav-right">
					<ul>
						<li><a href="monitoring.html" v-if="uInfoData.loginType !=1">监测</a></li>
						<li><a href="historical_data.html" v-if="uInfoData.loginType !=1">历史数据</a></li>
						<li><a href="historical_info.html" v-if="uInfoData.loginType == 1">历史数据</a></li>
						<li><a href="call_p.html">离床报警</a></li>
						<li><a href="call_p.html">离床报警</a></li>
						<li><a href="#">康养中心</a></li>
						<li><a href="#">中医问诊</a></li>
					</ul>
				</div>
				<div class="userinfo" id="userinfo">
					<img src="static/image/user.png" />
					<!-- <div class="red-dot"></div> -->
					<ul class="user_dropdown">
						<li class="dropdown_item user_ctrl">
							<div class="nickname">{{uInfoData.userName}}</div>
							<div class="sign_out">退出</div>
						</li>
						<li class="dropdown_item msg_item">
							<a href="user.html" target="_blank">
								<span>个人中心</span>
							</a>
						</li>
						<li class="dropdown_item msg_item">
							<a href="my_message.html" target="_blank">
								<span>我的消息</span>
								<span class="msg_unread unread_count show">5</span>
							</a>
						</li>
						<li class="dropdown_item">
							<a href="equipment.html">
								<span>设备</span>
							</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="static/js/config.js"></script>
		<script>
			$(function() {
				$("#pnav").load("public_navigation.html");
				$(".sign_out").click(function() {
					localStorage.clear();
					window.location = 'login.html'
				});
			});
			var vm = new Vue({
				el: '#app', //设置当前vue对象可以操作数据的范围,注意不要把vue对象绑定到body中，因为这样，vue需要控制整个页面的内容，效率太低了
				data: {
					uInfoData: [],
					ufInfoData: [],
					isleader: 3

				},
				ready: function() {
					// this.getdata();
				},
				created: function() {
					this.getdata();
				},
				methods: {
					getdata: function() {
						var rloginName = localStorage.loginName;
						var familyId = localStorage.familyId;
						console.log(rloginName);
						console.log(familyId);
						axios({
								method: 'GET',
								url: url + "/user/userInfo/lquserOwnInfo?phoneNum=" + rloginName,
								data: {}
							})
							.then(function(response) {
								console.log(response)
								vm.uInfoData = response.data;
								console.log(response.data.isleader)

							})
						let datass = new FormData();
						datass.append('userId', rloginName)
						datass.append('familyId', familyId)

						axios({
								method: 'post',
								url: url + "/family/getThisUserIsLeader",
								data: datass
							})
							.then(function(response) {
								console.log(response)
								vm.uInfoData = response.data;
								if (response.data.isleader == null) {
									vm.isleader = 3;
								} else {
									vm.isleader = parseInt(response.data.isleader);
								}
								console.log(response.data.isleader)
								console.log(vm.isleader)

							})
						let datas = new FormData();
						datas.append('familyId', familyId)
						axios({
								method: 'POST',
								url: url + "/family/familyMemberInfo",
								data: datas
							})
							.then(function(response) {
								console.log(response)
								vm.ufInfoData = response.data;
							})
					},
					Setmanagement: function(memberPhone, isleader) {
						var rloginName = localStorage.loginName;
						var equName = localStorage.userEquipment;
						var familyId = localStorage.familyId;
						let datas = new FormData();
						datas.append('familyId', familyId)
						datas.append('equName', equName)
						datas.append('userPhone', rloginName)
						datas.append('addPowerPhone', memberPhone)
						datas.append('isleader', isleader)
						layer.msg('您确定修改此成员权限吗？', {
							time: 0,
							btn: ['确定', '取消'],
							yes: function(index) {
								axios({
										method: 'POST',
										url: url + "/family/updateAdminUser",
										data: datas
									})
									.then(function(response) {
										console.log(response)
										var message = response.data.message
										if (response.data.code == 0) {
											layer.msg(message, {
												time: 2000,
												end: function() {
													location.href =
														'family_management.html'
												}
											})
										} else {
											layer.msg(message);
										}
									})
							}
						});

					},
					deldata: function(memberPhone) {
						var rloginName = localStorage.loginName;
						var familyId = localStorage.familyId;
						let datas = new FormData();
						datas.append('phoneNum', rloginName)
						datas.append('memberPhone', memberPhone)
						datas.append('familyId', familyId)

						layer.msg('您确定要删除此家庭组成员？', {
							time: 0 //不自动关闭
								,
							btn: ['确定', '取消'],
							yes: function(index) {
								axios({
										method: 'POST',
										url: url + "/family/familydelMember",
										data: datas
									})
									.then(function(response) {
										console.log(response)
										var message = response.data.message
										if (response.data.code == 0) {
											layer.msg(message, {
												time: 2000,
												end: function() {
													location.href =
														'family_management.html'
												}
											})
										} else {
											layer.msg(message);
										}
									})
							}
						});
					},
					delfamilydata: function(fname) {
						var rloginName = localStorage.loginName;
						layer.msg('你确定删除家庭组？', {
							time: 0 ,	//不自动关闭
							btn: ['确定', '取消'],
							yes: function(index) {
						 	layer.close(index);
								let datas = new FormData();
								datas.append('userId', rloginName)
								datas.append('familyName', fname)
								axios({
										method: 'POST',
										url: url + "/family/delFamily",
										data: datas
									})
									.then(function(response) {
										var message = response.data.message;
										layer.msg(message, {
											time: 1000,
						  			end: function() {
												location.href =
													'family_management_list.html'
											}
										})
									})
							}
						});
					
					}
				}
			})
		</script>
	</body>
</html>
